﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace QuanLyThongTinNhanKhau.GUI
{
    public partial class MainProgram : Form
    {
        String tagetFrm = null;
        GUI.NhanKhau nhanKhau;
        GUI.HoKhau hoKhau;
        GUI.Login login;
        GUI.TKTamTru tkTamTru;
        GUI.TKTamVang tkTamVang;
        GUI.TKChungTu tkChungTu;
        GUI.TKTATS tkTATS;

        String tenDangNhap = null;

        public MainProgram()
        {
            login = new Login();
            login.sendData += inputData;
            login.ShowDialog();

            InitializeComponent();
        }

        private void MainProgram_Load(object sender, EventArgs e)
        {
            showForm("HoKhau");

            if (tenDangNhap == null)
            {
                this.Close();
            }
        }

        private void inputData(object sender, string str)
        {
            tenDangNhap = str;
        }

        private void btnQLHoKhau_Click(object sender, EventArgs e)
        {
            showForm("HoKhau");
        }

        private void btnQLNhanKhau_Click(object sender, EventArgs e)
        {
            showForm("NhanKhau");
        }

        public void showForm(String str)
        {
            if (str == "NhanKhau" && tagetFrm != "NhanKhau")
            {
                tagetFrm = "NhanKhau";
                this.panelCenter.Controls.Clear();
                nhanKhau = new GUI.NhanKhau();
                nhanKhau.TopLevel = false;
                nhanKhau.AutoScroll = true;
                this.panelCenter.Controls.Add(nhanKhau);
                nhanKhau.Show();
            }
            else if (str == "HoKhau" && tagetFrm != "HoKhau")
            {
                tagetFrm = "HoKhau";
                this.panelCenter.Controls.Clear();
                hoKhau = new GUI.HoKhau();
                hoKhau.TopLevel = false;
                hoKhau.AutoScroll = true;
                this.panelCenter.Controls.Add(hoKhau);
                hoKhau.Show();
            }
            else if (str == "TKTamTru" && tagetFrm != "TKTamTru")
            {
                tagetFrm = "TKTamTru";

                this.panelCenter.Controls.Clear();
                tkTamTru = new GUI.TKTamTru();
                tkTamTru.TopLevel = false;
                tkTamTru.AutoScroll = true;
                this.panelCenter.Controls.Add(tkTamTru);
                tkTamTru.Show();
            }
            else if (str == "TKTamVang" && tagetFrm != "TKTamVang")
            {
                tagetFrm = "TKTamVang";

                this.panelCenter.Controls.Clear();
                tkTamVang = new GUI.TKTamVang();
                tkTamVang.TopLevel = false;
                tkTamVang.AutoScroll = true;
                this.panelCenter.Controls.Add(tkTamVang);
                tkTamVang.Show();
            }
            else if (str == "TKChungTu" && tagetFrm != "TKChungTu")
            {
                tagetFrm = "TKChungTu";

                this.panelCenter.Controls.Clear();
                tkChungTu = new GUI.TKChungTu();
                tkChungTu.TopLevel = false;
                tkChungTu.AutoScroll = true;
                this.panelCenter.Controls.Add(tkChungTu);
                tkChungTu.Show();
            }
            else if (str == "TKTATS" && tagetFrm != "TKTATS")
            {
                tagetFrm = "TKTATS";

                this.panelCenter.Controls.Clear();
                tkTATS = new GUI.TKTATS();
                tkTATS.TopLevel = false;
                tkTATS.AutoScroll = true;
                this.panelCenter.Controls.Add(tkTATS);
                tkTATS.Show();
            }
        }

        private void btnBCTamTru_Click(object sender, EventArgs e)
        {
            showForm("TKTamTru");
        }

        private void btnBCTamVang_Click(object sender, EventArgs e)
        {
            showForm("TKTamVang");
        }

        private void btnBCChungTu_Click(object sender, EventArgs e)
        {
            showForm("TKChungTu");
        }

        private void btnBCTATS_Click(object sender, EventArgs e)
        {
            showForm("TKTATS");
        }
    }
}
